﻿using System.Data;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;

namespace AD.EngenhariaTransito
{
    public class Pessoa
    {

        public static DataSet PessoaCadastro(string Nome, string DataNascimento, string Sexo,
                                          string NroCarteiraHabilitacao, string DataPrimeiraHabilitacao,
                                          int IdEndereco, string NroEndereco, string ComplementoEndereco, string Email)
        {
            Database myDatabase = DatabaseFactory.CreateDatabase();
            DbCommand myCommand = myDatabase.GetStoredProcCommand("dbo.proc_PessoaCadastro");

            myDatabase.AddInParameter(myCommand, "@Nome", DbType.String, Nome);
            myDatabase.AddInParameter(myCommand, "@DataNascimento", DbType.String, DataNascimento);
            myDatabase.AddInParameter(myCommand, "@Sexo", DbType.String, Sexo);
            myDatabase.AddInParameter(myCommand, "@NroCarteiraHabilitacao", DbType.String, NroCarteiraHabilitacao);
            myDatabase.AddInParameter(myCommand, "@DataPrimeiraHabilitacao", DbType.String, DataPrimeiraHabilitacao);
            myDatabase.AddInParameter(myCommand, "@IdEndereco", DbType.Int32, IdEndereco);
            myDatabase.AddInParameter(myCommand, "@NroEndereco", DbType.String, NroEndereco);
            myDatabase.AddInParameter(myCommand, "@ComplementoEndereco", DbType.String, ComplementoEndereco);
            myDatabase.AddInParameter(myCommand, "@Email", DbType.String, Email);

            DataSet ds = myDatabase.ExecuteDataSet(myCommand);
            return ds;
        }


        public static DataSet AgenteCadastro(int idPessoa, string registroIdentificacao, string codinomeAgente, string dataIntegracao, int idEstacaoTrabalho, string observacao)
        {
            Database myDatabase = DatabaseFactory.CreateDatabase();
            DbCommand myCommand = myDatabase.GetStoredProcCommand("dbo.proc_AgenteTransitoCadastro");

            myDatabase.AddInParameter(myCommand, "@IdPessoa", DbType.Int32, idPessoa);
            myDatabase.AddInParameter(myCommand, "@RegistroIdentificacao", DbType.String, registroIdentificacao);
            myDatabase.AddInParameter(myCommand, "@CodinomeAgente", DbType.String, codinomeAgente);
            myDatabase.AddInParameter(myCommand, "@DataIntegracao", DbType.String, dataIntegracao);
            myDatabase.AddInParameter(myCommand, "@idEstacao", DbType.Int32 , idEstacaoTrabalho);
            myDatabase.AddInParameter(myCommand, "@Observacao", DbType.String, observacao);

            DataSet ds = myDatabase.ExecuteDataSet(myCommand);
            return ds;
        }


        public static DataSet AgenteTransitoPesquisa(string nroFuncional, string nroDoc, string nroHabilitacao )
        {
            Database myDatabase = DatabaseFactory.CreateDatabase();
            DbCommand myCommand = myDatabase.GetStoredProcCommand("dbo.proc_AgenteTransitoPesquisa");

            if (nroFuncional == "")
                nroFuncional = "0";

            if (nroDoc == "")
                nroDoc = "0";

            if (nroHabilitacao == "")
                nroHabilitacao = "0";

            myDatabase.AddInParameter(myCommand, "@NroFuncional", DbType.Int32, nroFuncional);
            myDatabase.AddInParameter(myCommand, "@NroDoc", DbType.String, nroDoc);
            myDatabase.AddInParameter(myCommand, "@NroHabilitacao", DbType.String, nroHabilitacao); 

            DataSet ds = myDatabase.ExecuteDataSet(myCommand);
            return ds;
        } 

    }
}
